<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product media data template
 *
 * @see Mage_Catalog_Block_Product_View_Media
 */
?>
<?php

$product = $this->getProduct();
$helper  = $this->helper('catalog/output');

// Get the base image path
$baseImageFile = ($product->getImage() != 'no_selection' and $product->getImage()) ? $product->getImage() : false;

$galleryImages = array();

// Process the gallery images
foreach ($this->getGalleryImages() as $image) {
    if ($baseImageFile and $image->getFile() === $baseImageFile) {
        //only add images that aren't the baseImage
        continue;
    }

    $galleryImages[] = $image;
}

$baseImageSize = array(
    'x' => 736,
    'y' => 460,
);

$galleryImageSize = array(
    'x' => 95,
    'y' => 60,
);

$zoomSize = array(
    'x' => 940,
    'y' => 587,
);

$index = 0;

?>
<?php if ($baseImageFile): ?>
    <div class="product-image product-image-zoom">
        <a href="#product-media-modal" data-toggle="media" data-index="<?php echo $index++ ?>">
            <img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize($baseImageSize['x'], $baseImageSize['y']) ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel()) ?>" itemprop='photo' rel='image_src'>
        </a>
    </div>
<?php endif ?>

<?php if ($galleryImages): ?>
    <div class="more-views">
        <ul>
            <?php foreach ($galleryImages as $image): ?>
                <li>
                    <a href="#product-media-modal" data-toggle="media" data-index="<?php echo $index++ ?>">
                        <img src="<?php echo $this->helper('catalog/image')->init($product, 'image', $image->getFile())->resize($galleryImageSize['x'], $galleryImageSize['y']) ?>" alt="<?php echo $this->htmlEscape($image->getLabel()) ?>">
                    </a>
                </li>
            <?php endforeach ?>
        </ul>
    </div>
<?php endif ?>

<?php if ($baseImageFile || $galleryImages): ?>

    <div class="modal modal-media fade" id="product-media-modal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title"><?php echo $helper->productAttribute($product, $product->getName(), 'name') ?></h4>
                </div>
                <div class="modal-body">

                    <div id="product-media-carousel" class="carousel slide">
                        <ol class="carousel-indicators">
                            <?php $index = 0; ?>
                            <?php if ($baseImageFile): ?>
                                <li data-target="#product-media-carousel" class="active" data-slide-to="<?php echo $index++ ?>"></li>
                            <?php endif ?>
                            <?php $count = 0; ?>
                            <?php foreach ($galleryImages as $image): ?>
                                <li data-target="#product-media-carousel" class="<?php if ($index == $count): ?>active<?php endif ?>" data-slide-to="<?php echo $index++; ?>"></li>
                                <?php $count++; ?>
                            <?php endforeach ?>
                        </ol>

                        <div class="carousel-inner">
                            <?php $index = 0; ?>
                            <?php if ($baseImageFile): $index++; ?>
                                <div class="item active">
                                    <img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize($zoomSize['x'], $zoomSize['y']) ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel()) ?>">
                                </div>
                            <?php endif ?>
                            <?php foreach ($galleryImages as $image): ?>
                                <div class="item <?php if ($index++ == 0): ?>active<?php endif ?>">
                                    <img src="<?php echo $this->helper('catalog/image')->init($product, 'image', $image->getFile())->resize($zoomSize['x'], $zoomSize['y']) ?>" alt="<?php echo $this->htmlEscape($image->getLabel()) ?>">
                                </div>
                            <?php endforeach ?>
                        </div>

                        <?php if ($index > 1): ?>
                            <a class="left carousel-control" href="#product-media-carousel" data-slide="prev">
                                <span class="icon-prev"></span>
                            </a>
                            <a class="right carousel-control" href="#product-media-carousel" data-slide="next">
                                <span class="icon-next"></span>
                            </a>
                        <?php endif ?>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

<?php endif ?>
